home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / srefv112.zip / SREFPRC1.ZIP / OPENREAD.SRF < prev    next >
Text File  |  1996-05-10  |  2KB  |  68 lines

  1. /* ----------------------------------------------------------------------- */
  2. /* OPEN_READ: keep trying to open a file (for msec seconds
  3. .  astatus=open_read(afile,max_seconds)
  4. .  If success, astatus > 0 = # seconds it took
  5. .  If failure, astatus=-1 (no such file) or -2 (could not open)
  6. */
  7. /* ----------------------------------------------------------------------- */
  8.  
  9. sref_open_read:
  10. parse upper arg afile , msec , howopen .
  11. debug=0
  12.  
  13. howopen=translate(howopen)
  14.  
  15. if afile=0 | afile="" then do
  16.    if debug=1 then   say "OPEN_READ: No file name provided "
  17.    return -1             /*no such file flat */
  18. end
  19.  
  20. /* DISALLOW wildcarded files (they cause trouble below */
  21. if pos('*',afile)>0 | pos('?',afile)>0 then do
  22.     if debug=1 then  say "OPEN_READ: No wildcards allowed "
  23.     return -1
  24. end
  25.  
  26. isfile=stream(afile,'c','query exists') ;
  27. if howopen="NEW"  then do
  28.     if isfile="" then
  29.         isfile=afile
  30.     else do
  31.         if debug=1 then  say "OPEN_READ: NEW file already exists "
  32.        return -1
  33.     end  /* Do */
  34. end
  35. else do
  36.    if isfile=""  then do
  37.        if debug=1 then  say 'OPEN_READ: Could not find ' afile
  38.       return -1             /*no such file */
  39.    end 
  40. end
  41.  
  42. sec1=time('RESET')
  43. foy=time('ELAPSED')
  44.  
  45. do until time('ELAPSED') > msec
  46.     select
  47.     when howopen='BOTH' then
  48.        inuse=stream(isfile,'c','open')
  49.     when howopen='WRITE'| howopen="NEW" then do
  50.          inuse=stream(isfile,'c','open write')
  51.     end
  52.     otherwise do
  53.         inuse=stream(isfile,'c','open read')
  54.     end
  55.     end
  56.     if inuse<>'READY:' then do
  57.         wait seconds 1                  /* wait a second, and try again */
  58.         iterate
  59.       end
  60. /* Else, it's openable */
  61.     gog=time('ELAPSED')
  62.     return gog+0.01
  63. end
  64.  if debug=1 then  say " OPEN_READ: no time "
  65. return -2                /* could not open in alloted time */
  66.  
  67.  
  68.